package com.jsh.erp.service.depotHead;

import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.IdUtils;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service(value = "depotHead_component")
@DepotHeadResource
public class DepotHeadComponent implements ICommonQuery {

    @Resource
    private DepotHeadService depotHeadService;

    @Override
    public Object selectOne(String id) throws Exception {
        return depotHeadService.getDepotHeadById(id);
    }

    @Override
    public List<?> select(Map<String, String> map)throws Exception {
        return getDepotHeadList(map);
    }

    private List<?> getDepotHeadList(Map<String, String> map)throws Exception {
        String search = map.get(Constants.SEARCH);
        String type = StringUtil.getInfo(search, "type");
        String subType = StringUtil.getInfo(search, "subType");
        String roleType = StringUtil.getInfo(search, "roleType");
        String status = StringUtil.getInfo(search, "status");
        String purchaseStatus = StringUtil.getInfo(search, "purchaseStatus");
        String number = StringUtil.getInfo(search, "number");
        String linkNumber = StringUtil.getInfo(search, "linkNumber");
        String beginTime = StringUtil.getInfo(search, "beginTime");
        String endTime = StringUtil.getInfo(search, "endTime");
        String materialParam = StringUtil.getInfo(search, "materialParam");
        String organId =  StringUtil.getInfo(search, "organId");
        String creator =  StringUtil.getInfo(search, "creator");
        String depotId =  StringUtil.getInfo(search, "depotId");
        String accountId =  StringUtil.getInfo(search, "accountId");
        String remark = StringUtil.getInfo(search, "remark");
        String custom3 = StringUtil.getInfo(search, "custom3");
        String payStatus = StringUtil.getInfo(search, "payStatus");
        String freightStatus = StringUtil.getInfo(search, "freightStatus");
        String quotationStatus = StringUtil.getInfo(search, "quotationStatus");
        String custom4 = StringUtil.getInfo(search, "custom4");
        String color = StringUtil.getInfo(search, "color");
        String alwaysSelect = StringUtil.getInfo(search, "alwaysSelect");
        String itemType = StringUtil.getInfo(search, "itemType");
        String creditStatus = StringUtil.getInfo(search, "creditStatus");
        String depotStatus = StringUtil.getInfo(search, "depotStatus");
        String column = StringUtil.getInfo(search, "column");
        String order = StringUtil.getInfo(search, "order");

        return depotHeadService.select(type, subType, roleType, status, purchaseStatus, number, linkNumber, beginTime, endTime, materialParam,
                organId, creator, depotId, accountId, remark,custom3, QueryUtils.offset(map), QueryUtils.rows(map),payStatus,
                freightStatus,quotationStatus,custom4,color,alwaysSelect,itemType,creditStatus,depotStatus,column,order);
    }

    @Override
    public Long counts(Map<String, String> map)throws Exception {
        String search = map.get(Constants.SEARCH);
        String type = StringUtil.getInfo(search, "type");
        String subType = StringUtil.getInfo(search, "subType");
        String roleType = StringUtil.getInfo(search, "roleType");
        String status = StringUtil.getInfo(search, "status");
        String purchaseStatus = StringUtil.getInfo(search, "purchaseStatus");
        String number = StringUtil.getInfo(search, "number");
        String linkNumber = StringUtil.getInfo(search, "linkNumber");
        String beginTime = StringUtil.getInfo(search, "beginTime");
        String endTime = StringUtil.getInfo(search, "endTime");
        String materialParam = StringUtil.getInfo(search, "materialParam");
        String organId =  StringUtil.getInfo(search, "organId");
        String creator =  StringUtil.getInfo(search, "creator");
        String depotId =  StringUtil.getInfo(search, "depotId");
        String accountId =  StringUtil.getInfo(search, "accountId");
        String remark = StringUtil.getInfo(search, "remark");
        String custom3 = StringUtil.getInfo(search, "custom3");
        String payStatus = StringUtil.getInfo(search, "payStatus");
        String freightStatus = StringUtil.getInfo(search, "freightStatus");
        String quotationStatus = StringUtil.getInfo(search, "quotationStatus");
        String custom4 = StringUtil.getInfo(search, "custom4");
        String color = StringUtil.getInfo(search, "color");
        String alwaysSelect = StringUtil.getInfo(search, "alwaysSelect");
        String itemType = StringUtil.getInfo(search, "itemType");
        String creditStatus = StringUtil.getInfo(search, "creditStatus");
        String depotStatus = StringUtil.getInfo(search, "depotStatus");
        return depotHeadService.countDepotHead(type, subType, roleType, status, purchaseStatus, number, linkNumber, beginTime, endTime, materialParam,
                organId, creator, depotId, accountId, remark,custom3,payStatus,freightStatus,quotationStatus,custom4,color,alwaysSelect,itemType,creditStatus,
                depotStatus);
    }

      @Override
    public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
        obj.put("id", IdUtils.getUUID());
        return depotHeadService.insertDepotHead(obj, request);
    }

    @Override
    public int update(JSONObject obj, HttpServletRequest request)throws Exception {
        return depotHeadService.updateDepotHead(obj, request);
    }

    @Override
    public int delete(String id, HttpServletRequest request)throws Exception {
        return depotHeadService.deleteDepotHead(id, request);
    }

    @Override
    public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
        return depotHeadService.batchDeleteDepotHead(ids, request);
    }

    @Override
     public int checkIsNameExist(String id, String name) throws Exception{
        return depotHeadService.checkIsNameExist(id, name);
    }

}
